package com.phyane.home.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.phyane.common.baseopp.DataBaseOpp;
import com.phyane.home.param.ContentParam;

public class SendNewService {
	public int writeData(ContentParam param){
		int ret = 0;
		Connection conn = null;
		Statement st = null;
		StringBuffer sql = new StringBuffer("insert into main_content_tb values(null,'");
		sql.append(param.getImage()).append("','").append(param.getContent())
			.append("',").append(param.getAuthod()).append(")");;
		try {
			conn = DataBaseOpp.getConnection();
			st = conn.createStatement();
			st.execute(sql.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DataBaseOpp.closeConn(conn);
		}
		return ret;
	}
	
	public List<ContentParam> getData(){
		List<ContentParam> list = new ArrayList<ContentParam>();
		Connection conn = null;
		Statement st = null;
		ResultSet rst = null;
		StringBuffer sql = new StringBuffer("select * from main_content_tb");
		try {
			conn = DataBaseOpp.getConnection();
			st = conn.createStatement();
			rst = st.executeQuery(sql.toString());
			while(rst.next()){
				ContentParam param = new ContentParam();
				param.setAuthod(rst.getInt("auth_id"));
				param.setContent(rst.getString("text"));
				param.setImage(rst.getString("picture"));
				list.add(param);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DataBaseOpp.closeConn(conn);
		}
		return list;
	}
}
